console.log('1111');

const readfile=(file)=>{
    return new Promise((resolve,reject)=>{
        console.log('jinlaile');
        const readFile=new FileReader(file)
            readFile.onload=(e)=>{
                resolve(e.target.result)
            }
            readFile.onerror=reject
            readFile.readAsBinaryString(file)
    })
    
}


file.addEventListener('change',async (event)=>{
const {name,type,size} =file.files[0]
progress.max=size
const contents=await readfile(file.files[0])
const JMcontent=CryptoJS.SHA256(contents)
let indexSize= +localStorage.getItem(JMcontent)
h1Message.innerText='上传中...'
    while(indexSize<size){
        let content =file.files[0].slice(indexSize,indexSize+500,type)
        // let obj= {
        //     name,type,indexSize,content
        // }
            console.log("-----",content);
        let Data =new FormData()
        Data.append('name',name)
        Data.append('type',type)
        Data.append('indexSize',indexSize)
        Data.append('file',content)
        Data.append('hash',JMcontent)
        
        try {
           
            await axios.post('/updata',Data)
        } catch (error) {
                h1Message.innerText='上传失败:'+error
                return
        }
        indexSize+=500
        progress.value=indexSize
        localStorage.setItem(JMcontent,indexSize)
      
}
h1Message.innerText='上传成功!!'
// localStorage.removeItem(JMcontent)
})


const updata=()=>{
    console.log('11111');
}